package com.summer.data.table.column;

import com.summer.data.jql.behavior.FilterAble;
import com.summer.data.jql.concept.exp.FixedLikeFilterExp;
import com.summer.data.jql.concept.exp.LeftLikeFilterExp;
import com.summer.data.jql.concept.exp.LikeFilterExp;
import com.summer.data.jql.concept.exp.RightLikeFilterExp;
import com.summer.data.table.BaseColumn;

import java.sql.Clob;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author 345480567@qq.com
 */

public class ClobColumn extends BaseColumn<String> {

    public ClobColumn(String colName) {
        super(colName);
    }

    @Override
    public void fetchNotNullValue(ResultSet resultSet, Integer index) throws SQLException {
        Clob clob = resultSet.getClob(index);
        if (clob != null) {
            int len = Math.toIntExact(clob.length());
            value = clob.getSubString(1, len);
        }
    }

    public static String getValue(ResultSet resultSet, Integer index) throws SQLException {
        Clob clob = resultSet.getClob(index);
        int len = Math.toIntExact(clob.length());
        return clob.getSubString(1, len);
    }

    public FilterAble like(String param) {
        return new LikeFilterExp(this, param);
    }

    public FilterAble leftLike(String value) {
        return new LeftLikeFilterExp(this, value);
    }

    public FilterAble rightLike(String value) {
        return new RightLikeFilterExp(this, value);
    }

    public FilterAble fixedLike(int leftFix, String param, int rightFix) {
        return new FixedLikeFilterExp(this, param, leftFix, rightFix);
    }

}
